<!--
档案管理-档案分类增加
 add by yyp 2020-01-10
-->
<template lang="pug">
  kalix-dialog.user-add(bizKey="Class" ref="kalixBizDialog"
  v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL")
    div.el-form(slot="dialogFormSlot" style=" width:60%;margin:auto;")
      el-form-item(label="档案分类" prop="className" label-width="labelWidth" v-bind:rules="rules.className")
        el-input(v-model="formModel.className" style="width:80%")
</template>

<script type="text/ecmascript-6">
  import FormModel from './model'
  import {ClassURL} from '../../config.toml'
  import KalixClansmanUpload from '../../../../../components/fileUpload/upload'
  import {baseURL} from '../../../../../config/global.toml'
  import KalixSelect from '../../../../../components/corelib/components/common/baseSelect'
  export default {
    name: 'classAdd',
    components: {KalixSelect, KalixClansmanUpload},
    data() {
      let validateClasslName = (rule, value, callback) => {
        if (value === null) {
          callback(new Error('请输入档案分类名称'))
        } else {
          this.axios.request({
            method: 'GET',
            url: ClassURL + '/existClassBean/',
            data: '',
            params: {
              className: value
            }
          }).then(response => {
            if (response.data) {
              callback(new Error('该分类名称已被使用'))
            } else {
              callback()
            }
          }).catch(() => {
          })
        }
      }
      return {
        formModel: Object.assign({}, FormModel),
        action: baseURL + '/camel/rest/upload',
        rules: {
          // className: [{required: true, name: '请输入名称', trigger: 'blur'}]
          className: [{required: true, validator: validateClasslName, trigger: 'blur'}]
        },
        targetURL: ClassURL,
        labelWidth: '110px'
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
  .el-form
    width 70%
    margin auto
    .el-input
      width 70%
    .radio
      margin-left 20px
      .el-radio
        color: #3465cb
        font-weight: bold
        font-size: 14px
</style>
